package com.guigu.ssyx.product.controller;


import com.atguigu.ssyx.vo.product.AttrGroupQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.ssyx.common.result.Result;
import com.guigu.ssyx.product.entity.AttrGroup;
import com.guigu.ssyx.product.service.AttrGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author liuyang
 * @since 2025-09-10
 */
@RestController
@RequestMapping("/admin/product/attrGroup")
public class AttrGroupController {

    @Autowired
    private AttrGroupService attrGroupService;
    /**
     * 查询所有属性分组
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page, @PathVariable Long limit, AttrGroupQueryVo attrGroupQueryVo){

        Page<AttrGroup> attrGroupPage = new Page<>(page, limit);

        IPage<AttrGroup> list = attrGroupService.selectPage(attrGroupPage, attrGroupQueryVo);

        return Result.ok(list);
    }

    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        AttrGroup attrGroup = attrGroupService.getById(id);
        return Result.ok(attrGroup);
    }

    @PostMapping("save")
    public Result save(@RequestBody AttrGroup attrGroup){
        attrGroupService.save(attrGroup);
        return Result.ok(null);
    }

    @PutMapping("update")
    public Result updateById(@RequestBody AttrGroup attrGroup){
        attrGroupService.updateById(attrGroup);
        return Result.ok(null);
    }

    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        attrGroupService.removeById(id);
        return Result.ok(null);
    }

    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody Long[] ids){
        attrGroupService.removeByIds(java.util.Arrays.asList(ids));
        return Result.ok(null);
    }

   @GetMapping("findAllList")
    public Result findAllList(){
         return Result.ok(attrGroupService.list());
    }


}

